package com.umbr3lla.network.socket;


import com.umbr3lla.network.actions.ClientAction;

public class ClientSocketMessage {

	// ID     PLAYERID  SIZE    PAYLOAD
	//[bytes | byte | 4 bytes | .... ]
	public static byte[] createBinaryMessage(ClientAction action, byte playerID)
	{
		byte[] payload = action.getPayload();
		int value = payload.length;
		byte[] header = {action.id, playerID,
				(byte)(value >>> 24),
                (byte)(value >>> 16),
                (byte)(value >>> 8),
                (byte)value};
		
		byte[] message = new byte[6 + payload.length];
		System.arraycopy(header, 0, message, 0, header.length);
		System.arraycopy(payload, 0, message, header.length, payload.length);	
			
		return message;
	}
	
}